import { MockMethod } from 'vite-plugin-mock';

export default [
  {
    // 登录接口
    url: '/mock/api/login',
    method: 'post',
    timeout: 1000,
    response: ({ body }) => {
      if (body.username === 'admin') {
        return {
          code: 200,
          message: '登录成功',
          data: {
            username: 'admin',
            accessToken: 'admin',
            roles: ['admin']
          }
        };
      } else if (body.username !== body.password) {
        return {
          code: 1,
          message: '用户名和密码不匹配',
          data: {
            username: '',
            accessToken: '',
            roles: []
          }
        };
      } else {
        return {
          code: 0,
          message: 'token失效',
          data: {
            username: '',
            accessToken: '',
            roles: []
          }
        };
      }
    }
  }
] as MockMethod[];
